﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;

using System.Xml.Linq;
using System.Text.RegularExpressions;
using System.Text;
using System.Collections.Generic;

namespace NOAH.CMS.Repository
{
    /// <summary>
    /// Summary description for BaseEntity
    /// </summary>
    public class BaseEntity 
    {
        //public DateTime ModifiedDate { get; set; }

        protected string BuildSEO(string convertedString)
        {
            if (string.IsNullOrEmpty(convertedString)) convertedString = "";
            string subject = convertedString.Trim();

            if (subject.Length > 180)
                subject = subject.Substring(0, 180);

            Regex regex = new Regex(@"\p{IsCombiningDiacriticalMarks}+");
            string strFormD = subject.Normalize(System.Text.NormalizationForm.FormD);
            subject = regex.Replace(strFormD, String.Empty).Replace('\u0111', 'd').Replace('\u0110', 'D');

            subject = Regex.Replace(subject, @"\s+", "-");
            subject = Regex.Replace(subject, @"[^A-Za-z0-9_-]", "");
            //subject = Regex.Replace(subject, @"-", " ");

            return subject;
        }

        //public string BuildSEO(string convertedString)
        //{
        //    Regex regex = new Regex(@"\p{IsCombiningDiacriticalMarks}+");
        //    Regex rgx = new Regex("[^a-zA-Z0-9 -]");

        //    string strFormD = convertedString.Normalize(System.Text.NormalizationForm.FormD);
        //    strFormD = regex.Replace(strFormD, String.Empty).Replace('\u0111', 'd').Replace('\u0110', 'D');
        //    strFormD = rgx.Replace(strFormD, " ");

        //    return strFormD.Replace("-", string.Empty);//.Replace(@"""", string.Empty).Replace("-", string.Empty).Replace("?", string.Empty).Replace("%", "").Replace(":", "").Replace("/","")
        //}

        //public string BuildSEO(object convertedString)
        //{
        //    if (convertedString == null) return "";
        //    string convert = convertedString.ToString();
        //    Regex regex = new Regex(@"\p{IsCombiningDiacriticalMarks}+");
        //    string strFormD = convert.Normalize(System.Text.NormalizationForm.FormD);
        //    return regex.Replace(strFormD, String.Empty).Replace('\u0111', 'd').Replace('\u0110', 'D').Replace(@"""", string.Empty).Replace("-", string.Empty).Replace("?", string.Empty).Replace("%", "").Replace(":", "");
        //}
    }

}